<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //字符串字母出现次数求和
        let str = 'asdasdasdasdasdasd'
        let arrStr = str.split("")
        const newArr = arrStr.reduce((pre, cur, index, arr) => {
            if (pre.hasOwnProperty(cur)) {
                pre[cur]++
            } else {
                pre[cur] = 1
            }
            return pre
        }, {})
        console.log(newArr)
        //组内求和
        let arr = [{ a: 100 }, { a: 20 }, { a: -10 }]
        const sum = arr.reduce((pre, cur, index, arr) => {
            return pre + cur.a
        }, 0)
        console.log(sum)
    </script>
</body>

</html>